﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Gestion.Ui;


    public partial class Editor_IntegerEditor : BaseUserControl
    {
        #region Properties

        public String Text
        {
            get
            {
                return EditorTextBox.Text;
            }
        }

        public String Label
        {
            set
            {
                EditorLabel.Text = value;
            }
            get
            {
                return EditorLabel.Text;
            }
        }

        public Int32 Value
        {
            set
            {
                EditorTextBox.Text = String.Format("{0}", value);
            }
            get
            {
                int res;
                Int32.TryParse(EditorTextBox.Text, out res);
                return res;
            }
        }

        private Boolean _isRequired = true;
        public Boolean IsRequired
        {
            set
            {
                _isRequired = value;
            }
            get
            {
                return _isRequired;
            }
        }
        private Int64 minValue=-2147483648;
        public Int64 MiniumValue
        {
            get { return minValue; }
            set { EditorRangeValidator.MinimumValue = value.ToString(); }
        }

        private Int64 maxValue = 2147483648;
        public Int64 MaxiumValue
        {
            get { return maxValue; }
            set { EditorRangeValidator.MaximumValue = value.ToString(); }
        }


        public String ErrorMsgRequiredValidator
        {
            set
            {
                EditorRequiredFieldValidator.ErrorMessage = value;
            }
            get
            {
                return EditorRequiredFieldValidator.ErrorMessage;
            }
        }

        public String ErrorMsgRangeValidator
        {
            set
            {
                EditorRangeValidator.ErrorMessage = value;
            }
            get
            {
                return EditorRangeValidator.ErrorMessage;
            }
        }

        public Boolean Enabled
        {
            set
            {
                EditorRangeValidator.Enabled = value;
                EditorRequiredFieldValidator.Enabled = value;
                EditorTextBox.Enabled = value;
            }
            get
            {
                return EditorTextBox.Enabled;
            }
        }

        public System.Web.UI.WebControls.Unit Height
        {
            set
            {
                EditorTextBox.Height = value;
            }
            get
            {
                return EditorTextBox.Height;
            }
        }

        public System.Web.UI.WebControls.Unit Width
        {
            set
            {
                EditorTextBox.Width = value;
            }
            get
            {
                return EditorTextBox.Width;
            }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                EditorRequiredFieldValidator.Enabled = IsRequired;
        }

        public void Reset()
        {
            EditorTextBox.Text = "";
        }
    }
